<template>
  <div class="common-layout">
    <el-container>
      <el-header>
        <el-button type="primary" @click="logout">退出登录</el-button>
      </el-header>
      <el-container>
        <el-aside width="200px">
          <el-menu
            default-active="2"
            class="el-menu-vertical-demo"
            @open="handleOpen"
            @close="handleClose"
          >
          <el-sub-menu :index="key" v-for="(item, key) in resources" :key="key">
            <template #title>
              <el-icon><location /></el-icon>
              <span>{{ item.pname }}</span>
            </template>
            <el-menu-item :index="key" v-for="(item2, key) in item.son" :key="key">
              <router-link :to="item2.url">{{ item2.name }}</router-link>
            </el-menu-item>
          </el-sub-menu>
          <el-sub-menu>
            <template #title>
              <el-icon><location /></el-icon>
              <span><router-link to="/workflowlist">工作台</router-link></span>
            </template>
          </el-sub-menu>
        </el-menu>
        </el-aside>
        <el-main><router-view></router-view></el-main>
      </el-container>
    </el-container>
  </div>
</template>

<script setup>
  import { ref, onMounted } from "vue"
  import axios from "axios"
  import { useRoute, useRouter } from "vue-router";
  import http from "../http"

  const route = useRoute()
  const router = useRouter()

  // let role_id = route.query.role

  let resources = ref([])

  let workflow = ref([])

  resources.value = JSON.parse(localStorage.getItem("pid_list"))

  const logout = () =>{
    // localStorage.removeItem("token")
    let token = localStorage.getItem("token")
    http.post(`myadmin/logout/`, {token: token})
    .then(res=>{
      console.log(res)
      router.push("/")
    })
  }

  // const getresources = () =>{
  //   http.post(`myadmin/get_resource/`, {"role_id": role_id})
  //   .then(res=>{
  //     console.log(res.data)
  //     resources.value = res.data.pid_list
  //     url_list = res.data.url_list
  //     localStorage.setItem("url_list", JSON.stringify(url_list))
  //   })
  //   .catch(error=>{
  //     console.log(error)
  //   })
  // }

  // onMounted(()=>{
  //   getresources()
  // })

</script>